


class SetOperation{
    constructor(){

    }
    unique(setA,setB){
        return new Set([...setA,...setB])
    }
    intersect(setA,setB){
        const arr = [...setA].filter(item=>setB.has(item))
        return new Set(arr)
    }
    difference(setA,setB){
        const arr = [...setA].filter(item=>!setB.has(item))
        return new Set(arr)
    }
    subset(setA,setB){
        let valuesB = [...setB]
        for(let i=0;i<valuesB.length;i++){
            let item = valuesB[i]
            if(!setA.has(item)){
                return false
            }
        }
        return true
    }
}

const setA = new Set([1,2,3,7])
const setB= new Set([1,2,3,4,5,6])
const setC= new Set([1])

const setOperation = new SetOperation()

//并集
const resultUnique = setOperation.unique(setA,setB)
console.log('并集',resultUnique)

//交集
const resultIntersect = setOperation.intersect(setA,setB)
console.log('交集',resultIntersect)

//差集
let resultDifference = setOperation.difference(setA,setB)
console.log('差集',resultDifference)

 resultDifference = setOperation.difference(setB,setA)
console.log('差集',resultDifference)

let resultSubset  = setOperation.subset(setB,setA)
console.log('子集',resultSubset)
resultSubset  = setOperation.subset(setB,setC)
console.log('子集',resultSubset)